<template>
  <view>
    <view class="list-card" v-if="!!list.length">
      <uni-card
        v-for="(item, index) in list"
        :key="index"
        :title="'预检单号：' + item.qualityOrderNo"
        @click="quality(item.id, item.inBillState)"
      >
        <view class="item">
          <view class="item-content">
            <label>状态：</label>
            <text
              class="status"
              :class="{ warning: item.inBillState < '300' }"
              >{{ item.inBillStateName || '-' }}</text
            >
          </view>
          <view class="item-content">
            <label>入库单号：</label>
            <text>{{ item.billNo || '-' }}</text>
          </view>
        </view>
        <view class="item">
          <view>
            <label>供应商：</label>
            <text>{{ item.supplierName || '-' }}</text>
          </view>
          <view class="item-content">
            <label>外部单号：</label>
            <text>{{ item.outOrderNo || '-' }}</text>
          </view>
        </view>
      </uni-card>
      <uni-load-more :status="loadMoreStatus"></uni-load-more>
    </view>
    <no-data
      :visible="!list.length"
      title="暂无数据"
      :fullscreen="true"
    ></no-data>
  </view>
</template>

<script>
import uniCard from '@/components/uni-card/uni-card.vue';
import loadMore from '@/components/uni-load-more/uni-load-more.vue';
import noData from '@/components/no-data/no-data.vue';

export default {
  components: {
    uniCard,
    loadMore,
    noData
  },
  props: {
    firstLoad: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      params: {},
      list: [],
      loadMoreStatus: global.$loadMoreStatus.more
    };
  },
  watch: {
    firstLoad: {
      handler() {
        this.load({
          limit: global.$limit,
          page: 1,
          warehouseId: this.$storage.getWarehouseId()
        });
      },
      immediate: true
    }
  },
  methods: {
    load(params = {}) {
      this.params = params;
      this.fetch();
    },
    fetch() {
      this.$api.quality.qualityList(this.params).then(
        res => {
          this.params.page === 1 &&
            uni.pageScrollTo({
              scrollTop: 0,
              duration: 300
            });
          this.list =
            this.params.page === 1
              ? [...res.data]
              : [...this.list, ...res.data];
          this.loadMoreStatus = this.$pageHelper.lastPage(
            this.params.limit,
            this.params.page,
            res.count
          )
            ? global.$loadMoreStatus.noMore
            : global.$loadMoreStatus.more;
          uni.hideLoading();
          uni.stopPullDownRefresh();
        },
        () => {
          uni.hideLoading();
          uni.stopPullDownRefresh();
        }
      );
    },
    quality(id, status) {
      if (status < '300') {
        uni.navigateTo({
          url: '/pages/inWarehouse/quality/preQuality?id=' + id
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.list-card /deep/ .uni-card {
  margin: 0 0 30rpx 0;
}

.list-card /deep/ .uni-card .uni-card__header {
  padding: 10rpx 24rpx;
}

.uni-load-more {
  margin-top: -30rpx;
}
</style>
